package com.example.wanbaqian.activity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.example.wanbaqian.R;
import com.example.wanbaqian.base.BaseActivity;
import com.example.wanbaqian.bean.SharedBean;
import com.example.wanbaqian.customView.CustomImageView;
import com.example.wanbaqian.customView.FindCodeView;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;

import butterknife.BindView;

/**
 * 邀请界面
 */
public class FindInviteActivity extends BaseActivity {
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.iv_head)
    CustomImageView ivHead;
    @BindView(R.id.fcv_code)
    FindCodeView fcvCode;
    private SharedBean sharedBean;

    @Override
    protected int getLayout() {
        return R.layout.activity_findinvite;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        sharedBean = (SharedBean) getIntent().getExtras().getSerializable("bean");
        setStatusBarColor(R.color.main_color);
        setToolBar("分享邀请");
        toolBar_btnRight.setBackgroundResource(R.drawable.more);
        toolBar_btnRight.setVisibility(View.VISIBLE);
        toolBar_btnRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UMImage image = new UMImage(FindInviteActivity.this, R.mipmap.ic_launcher);//图片
                UMWeb web = new UMWeb(sharedBean.getInvite_url());
                web.setTitle(""+getResources().getString(R.string.app_wxjqb2));//标题
                web.setThumb(image);  //缩略图
                web.setDescription("解您燃眉之急！");//描述
                new ShareAction(FindInviteActivity.this).withMedia(web)
                        .setDisplayList(SHARE_MEDIA.QQ, SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE)
                        .setCallback(umShareListener).open();
            }
        });
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private UMShareListener umShareListener = new UMShareListener() {
        @Override
        public void onStart(SHARE_MEDIA platform) {
            //分享开始的回调
        }

        @Override
        public void onResult(SHARE_MEDIA platform) {
            showToast("分享成功了");
            Log.d("plat", "platform" + platform);
        }

        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
        }

        @Override
        public void onCancel(SHARE_MEDIA platform) {
            showToast("分享取消了");
        }
    };

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);

    }

    @Override
    protected void initDate() {
        tvPhone.setText(sharedBean.getLogin_mobile());
        Glide.with(mContext).load(sharedBean.getAvatar_url()).into(ivHead);
        Glide.with(mContext).load(sharedBean.getUser_qrcode()).asBitmap().into(new SimpleTarget<Bitmap>() {
            @Override
            public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                fcvCode.setPic(resource).Build();
            }
        });
    }
}
